﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace RemoteData.common.converter
{
    public class ShortToHexStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // 检查值是否为null
            if (value == null)
            {
                return string.Empty; // 或者返回你想要的默认值
            }
            if (value is short)
            {
                return string.Format("{0:X4}", (short)value);
            }
            if(value is int)
            {
                int i = (int)value;
                short s = (short)i;
                string str = ((short)s).ToString("X");
                return string.Format("{0:X4}", (short)s);
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

}
